﻿package com.tris.apevision.shapes 
{
	import flash.display.DisplayObject;
	import flash.display.LineScaleMode;
	import org.cove.ape.AbstractParticle;
	import org.cove.ape.SpringConstraint;
	import org.papervision3d.core.geom.Lines3D;
	import org.papervision3d.core.geom.renderables.Line3D;
	import org.papervision3d.core.math.Number2D;
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.core.render.data.RenderSessionData;
	import org.papervision3d.materials.special.LineMaterial;
	import org.papervision3d.objects.primitives.Cylinder;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.objects.DisplayObject3D;
	
	/**
	* ...
	* @author DefaultUser (Tools -> Custom Arguments...)
	*/
	public class AVSpringConstraint extends SpringConstraint
	{
		private var lines:Lines3D;
		private var point1:AVSpheroid;
		private var point2:AVSpheroid;
		private var radius:Number;
		
		
		public function AVSpringConstraint(
				scene:Scene3D,
				material:LineMaterial,
				p1:AVSpheroid,
				p2:AVSpheroid,
				r:Number = 0.5,
				height:Number = 100,
				segmentsW:Number = 8,
				segmentsH:Number = 6,
				topRadius:Number = -1,
				topFace:Boolean = true,
				bottomFace:Boolean = true,
				stiffness:Number = 0.5,
				collidable:Boolean = false,
				rectHeight:Number = 1,
				rectScale:Number = 1,
				scaleToLength:Boolean = false) 
		{
			super(p1, p2, stiffness, collidable, rectHeight, rectScale, scaleToLength);
			
			point1 = p1;
			point2 = p2;
			radius = r;
			
			lines = new Lines3D(material, "line");
			lines.addNewLine(radius, point1.px, point1.py, point1.pz, point2.px, point2.py, point2.pz);
			scene.addChild(lines);
		}
		
		override public function init():void
		{
			super.init();
			sprite.graphics.clear();
		}
		
		override public function paint():void
		{
			lines.removeAllLines();
			lines.addNewLine(radius, point1.px, -point1.py, point1.pz, point2.px, -point2.py, point2.pz);
		}
	}
	
}